import { searchinfo } from '~/api/search'
import { ref, computed } from 'vue'


export const keyWord = ref('')


export const activeIndex = ref(null)
export const list = ref(['活动', '生态', '课程', '赛事', '资讯'])
export const tapItems = (e) => {
    activeIndex.value = e
}

export const tableData = ref({})
export const loading = ref(false)

export function getList() {
    loading.value = true
    searchinfo({info:keyWord.value}).then(res => {
        if (res && res.code == '0000') {
            tableData.value = res.data.result
            if(tableData.value.activityCenterDmos.length>0){
                return activeIndex.value = 0
            }else if(tableData.value.companyEcologyDmos.length>0 ||tableData.value.industryEcologyDmos.length>0){
                return activeIndex.value = 1
            }else if(tableData.value.carefulLiveDmos.length>0){
                return activeIndex.value = 2
            }else if(tableData.value.matchCenterDmos.length>0){
                return activeIndex.value = 3
            }else if(tableData.value.realInfoDmos.length>0){
                return activeIndex.value = 4
            }else{
                return activeIndex.value = null
            }
        }
    }).finally(()=>{
        loading.value = false
    })
}


export const nowList = computed(() => {
    let List = []
    if(!tableData.value.activityCenterDmos) return []
    switch (activeIndex.value) {
        case 0:
            List = tableData.value.activityCenterDmos
                break;
        case 1:
            // let sass = tableData.value.companyEcologySaasDmos.map(v=>{
            //     v.istype = '1'
            //     return v
            // })
            let qiye = tableData.value.companyEcologyDmos.map(v=>{
                v.istype = '2'
                return v
            })
            let chanye = tableData.value.industryEcologyDmos.map(v=>{
                v.istype = '3'
                return v
            })
            List = [...qiye,...chanye]
                break;
        case 2:
            List = tableData.value.carefulLiveDmos
                break;
        case 3:
            List = tableData.value.matchCenterDmos
                break;
        case 4:
            List = tableData.value.realInfoDmos
                break;
    }
    return List
})
